﻿using System;
using System.Runtime.Remoting;
using RootfusAddinContracts;
using RootfusHostView;

namespace RootfusAddinHostAdapters
{
    public class PinDefinitionAddInAdapter
    {
        internal static PinDefinition ContractToViewAdapter(IPinDefinitionContract contract)
        {
            if (!RemotingServices.IsObjectOutOfAppDomain(contract)
                && contract.GetType().Equals(typeof(PinDefinitionHostViewToContractAdapter)))
            {
                return ((PinDefinitionHostViewToContractAdapter)contract).GetSourceView();
            }
            else
            {
                return new PinDefinitionContractToHostViewAdapter(contract);
            }
        }

        internal static IPinDefinitionContract ViewToContractAdapter(PinDefinition view)
        {
            if (!RemotingServices.IsObjectOutOfAppDomain(view)
                && view.GetType().Equals(typeof(PinDefinitionContractToHostViewAdapter)))
            {
                return ((PinDefinitionContractToHostViewAdapter)view).GetSourceContract();
            }
            else
            {
                return new PinDefinitionHostViewToContractAdapter(view); 
            }
        }
    }
}
